#ifndef  APPLEJACKOBJECT_HPP
# define APPLEJACKOBJECT_HPP

# include <SFML/Graphics.hpp>
# include <Box2D/Box2D.h>
# include "../datatree.hpp"
# include "../spriteanimate.hpp"
# include "../ressourceslist.hpp"

namespace Shiny
{
  namespace Applejack
  {
    class World;
    class ApplejackObject
    {
    public:
      ApplejackObject(World&, Data);
      ~ApplejackObject();

      sf::Vector2f                  position;
      sf::Vector2f                  halfSize;
      b2BodyType                    type;
      std::list<b2FixtureDef>       fixtures;
      bool                          isBullet;
      bool                          hasFixedRotation;
      SpriteAnimate::AnimationArray graphics;
      char                          collisionMask;

    private:
      World&                        _world;
      unsigned int                  _ratio;

      struct ObjectLoaderMethod
      {
        const std::string key;
        void              (ApplejackObject::*method)(Data);
      };

      struct str2shape
      {
        const std::string key;
        b2Shape*          (ApplejackObject::*method)(Data, unsigned int);
      };

      void                         LoadType(Data);
      void                         LoadShape(Data);
      void                         LoadFixedRotation(Data);
      void                         LoadBullet(Data);
      void                         LoadGraphics(Data);
      static ObjectLoaderMethod    objectLoaderMethods[];

      b2Shape*                     CreateBoxShape(Data data, unsigned int ratio);
      b2Shape*                     CreateCircleShape(Data data, unsigned int ratio);
      b2Shape*                     CreatePolygonShape(Data data, unsigned int ratio);
      static str2shape             shapeMap[];
      static char                  FixtureLoadCollisionMask(Data);
    };

    class ObjectList : public RessourceList<ApplejackObject>
    {
    public:
      ObjectList() {}

      void Load(World&, Data);
    };
  }
}

#endif
